home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
tex
/
td187src.lzh
/
FIG.I
< prev
next >
Wrap
Text File
|
1991-12-14
|
27KB
|
852 lines
IMPLEMENTATION MODULE FIG ;
(*
Versuch, ein bereits fertiges FIG-File zu interpretieren
und die Objekte zu übernehmen. Quick'n Dirty-Version.
Verbesserungen überall möglich und nötig... (JP)
Dieses Modul ist (C)'91 by Jens Pirnay
*)
FROM Dialoge IMPORT BusyStart, BusyEnd;
FROM Diverses IMPORT GetFSelText, NumAlert, min, max;
FROM FileIO IMPORT Fopen, EOF, AgainChar, Reset, Close,
ReadChar, UnixLine, ReadLn, AgainLine;
FROM ObjectUtilities IMPORT FillObject;
FROM Types IMPORT DrawObjectTyp, TextPosTyp,
ExtendedArraySize, CharArraySize,
CodeAryTyp, ObjectPtrTyp;
FROM SYSTEM IMPORT BYTE, WORD, ADDRESS , ADR ;
FROM Storage IMPORT ALLOCATE , DEALLOCATE ;
IMPORT CommonData ;
IMPORT GetFile;
IMPORT MathLib0 ;
IMPORT MagicConvert ;
IMPORT MagicDOS ;
IMPORT MagicStrings ;
IMPORT MagicSys ;
IMPORT Variablen ;
IMPORT mtAlerts;
FROM VectorFont IMPORT LoadFont, TextWidth, TextHeight, SetTextStyle,
SetFont, OutText, CreateText;
(**
IMPORT RTD;
**)
TYPE chset = SET OF CHAR;
CONST
Magic = -29564; (* Test auf ungültige Zahl *)
FMagic = -29564.0; (* Test auf ungültige Zahl *)
Integers = chset{'0'..'9','+','-'};
Reals = chset{'0'..'9','+','-','.'};
SolidLine = 0;
DashLine = 1;
DottedLine = 2;
OEllipse = 1;
TEllipseByRad = 1;
TEllipseByDia = 2;
TCircleByRad = 3;
TCircleByDia = 4;
OPolyline = 2;
TPolyline = 1;
TBox = 2;
TPolygon = 3;
TArcBox = 4;
OSpline = 3;
TOpenNormal = 1;
TClosedNormal = 2;
TOpenInterpol = 3;
TClosedInterpol = 4;
OText = 4;
TLeftJustified = 0;
TCenterJustified = 1;
TRightJustified = 2;
OArc = 5;
T3PointArc = 1;
OCompound = 6;
OEndCompound = -6;
VAR Filehandle : INTEGER;
PROCEDURE ExtractNumber(VAR str : ARRAY OF CHAR) : INTEGER;
VAR i, j, res : INTEGER;
temp : ARRAY [0..19] OF CHAR;
BEGIN
(**
RTD.Write('EN-In', str);
**)
res := Magic;
(* Zunächst Spaces weg *)
i := 0;
WHILE (str[i]=' ') OR (str[i] = 07C) DO INC(i); END;
temp := '';
j := 0;
WHILE str[i] IN Integers DO
temp[j] := str[i];
INC(i);
INC(j);
END;
temp[j] := 0C;
WHILE (str[i]=' ') OR (str[i] = 07C) DO INC(i); END;
IF i>0 THEN
MagicStrings.Delete(str, 0, i);
END;
(**
RTD.Write('EN-temp', temp);
**)
IF temp[0]<>0C THEN
res := MagicConvert.StrToInt(temp);
END;
(**
RTD.Write('EN-Out', str);
**)
RETURN res;
END ExtractNumber;
PROCEDURE ExtractFloat(VAR str : ARRAY OF CHAR) : LONGREAL;
VAR i, j : INTEGER;
res : LONGREAL;
temp : ARRAY [0..19] OF CHAR;
BEGIN
(**
RTD.Write('EF-In', str);
**)
res := FMagic;
(* Zunächst Spaces weg *)
i := 0;
WHILE (str[i]=' ') OR (str[i] = 07C) DO INC(i); END;
temp := '';
j := 0;
WHILE str[i] IN Reals DO
temp[j] := str[i];
INC(i);
INC(j);
END;
temp[j] := 0C;
WHILE (str[i]=' ') OR (str[i] = 07C) DO INC(i); END;
IF i>0 THEN
MagicStrings.Delete(str, 0, i);
END;
(**
RTD.Write('EF-temp', temp);
**)
IF temp[0]<>0C THEN
res := MagicConvert.StrToReal(temp);
END;
(**
RTD.Write('EF-Out', str);
**)
RETURN res;
END ExtractFloat;
PROCEDURE ParseFile(name : ARRAY OF CHAR) : BOOLEAN;
TYPE chset = SET OF CHAR;
VAR i : INTEGER;
ok, first : BOOLEAN;
upperleft : BOOLEAN;
forwarrow : BOOLEAN;
backwarrow : BOOLEAN;
pixperinch : INTEGER;
c : CHAR;
str, num : ARRAY [0..255] OF CHAR;
intArray : ARRAY [1..19] OF INTEGER;
forwArray : ARRAY [1..5] OF INTEGER;
backwArray : ARRAY [1..5] OF INTEGER;
realArray : ARRAY [1..19] OF LONGREAL;
charBuffer : ARRAY [0..255] OF CHAR;
Code : CodeAryTyp;
obj : ObjectPtrTyp;
Surround : ARRAY [0..3] OF INTEGER;
wx : INTEGER ;
wy : INTEGER ;
ww : INTEGER ;
wh : INTEGER ;
dum : INTEGER ;
pos : CARDINAL;
Version : CARDINAL;
maxx, minx,
maxy, miny : INTEGER;
MinX, MinY : INTEGER;
deltaX,
deltaY : INTEGER;
(* Allgemein gilt:
Falls forw_arrow = 1, so folgt eine Zeile:
%da1 %da2 %da3 %da4 %da5 (5)
%da1 : arrow_type
%da2 : arrow_style
%da3 : arrow_thickness
%da4 : arrow_width
%da5 : arrow_height
Falls backw_arrow = 1, ebenfalls.
*)
PROCEDURE GetLine;
BEGIN
str[0] := 0C;
IF NOT EOF THEN
ReadLn (Filehandle, str);
END;
END GetLine;
PROCEDURE GetNewLine;
BEGIN
REPEAT
GetLine;
UNTIL str[0] <> '#';
END GetNewLine;
PROCEDURE ScanStr(Format : ARRAY OF CHAR);
VAR i, nrint, nrreal : INTEGER;
BEGIN
(*
RTD.Write('ToScan', Format);
*)
FOR i := 1 TO 19 DO
intArray [i] := Magic;
realArray[i] := FMagic;
END;
nrint := 0;
nrreal := 0;
FOR i := 0 TO MagicSys.CastToInt(MagicStrings.Length(Format))-1 DO
IF (Format[i] = 'd') THEN
INC(nrint);
intArray[nrint] := ExtractNumber(str);
END;
IF (Format[i] = 'f') THEN
INC(nrreal);
realArray[nrreal] := ExtractFloat(str);
END;
END;
i := nrint + nrreal;
(*
RTD.ShowVar('Scanned', i);
*)
END ScanStr;
PROCEDURE Coord(integer : INTEGER) : INTEGER;
BEGIN
IF upperleft THEN
RETURN -integer;
ELSE
RETURN integer;
END;
END Coord;
PROCEDURE CheckArrow(forw, backw : INTEGER);
VAR i : INTEGER;
BEGIN
forwarrow := intArray[forw] =1;
backwarrow := intArray[backw]=1;
IF forwarrow THEN
GetNewLine;
FOR i:=1 TO 5 DO
forwArray[i] := ExtractNumber(str);
END;
END;
IF backwarrow THEN
GetNewLine;
FOR i:=1 TO 5 DO
backwArray[i] := ExtractNumber(str);
END;
END;
END CheckArrow;
PROCEDURE InitCode;
VAR i : INTEGER;
BEGIN
FOR i := 0 TO 9 DO Code[i] := 0; END;
FOR i := 0 TO 3 DO Surround[i] := 0; END;
Code[8] := 1; (* Thickness *)
END InitCode;
PROCEDURE GetArc;
VAR IsArc : BOOLEAN;
startangle, deltaangle : INTEGER;
radx, rady : INTEGER;
BEGIN
(* Format der Arc-Beschreibung:
%d01 %d02 %d03 %d04 %d05 %d06 %d07 %f01
%d08 %d09 %d10 %f02 %f03 %d11 %d12 %d13
%d14 %d15 %d16 (19)
mit
%d01 : type %d02 : line_style
%d03 : line_thickness %d04 : color
%d05 : depth %d06 : pen
%d07 : area_fill %f01 : style_val
%d08 : direction %d09 : forw_arrow
%d10 : backw_arrow %f02 : center_x
%f03 : center_y %d11 : x_1
%d12 : y_1 %d13 : x_2
%d14 : y_2 %d15 : x_3
%d16 : y_3
*)
ScanStr('dddddddfdddffdddddd');
CheckArrow(9, 10);
(*
InitCode;
Code[1] := RealCoord(realArray[2]);
Code[2] := RealCoord(realArray[3]);
IF (intArray[1] = T3PointArc) THEN
IF IsArc THEN
Code[0] := ORD(Arc);
Code[3] := radx;
Code[4] := startangle;
Code[5] := deltaangle;
Variablen.NewObject(Code, NIL, NIL, Surround);
Variablen.LastObject^.SurrDirty := TRUE;
ELSE
Code[0] := ORD(Ellipse);
Code[3] := radx;
Code[4]